package com.cat.dynamicPlanning;

import java.util.Arrays;

/**
*   @description https://leetcode.cn/problems/unique-substrings-in-wraparound-string/description/
*   @author 曲大人的喵
*   @create 2025/8/27 11:07
*   @since JDK17
*/

public class Solution09 {
    public int findSubstringInWraproundString(String str) {
        char[] s = str.toCharArray();
        int n = s.length, len = 1;
        int[] dp = new int[26];
        for (int i = 0; i < n; i++) {
            s[i] -= 'a';
        }
        dp[s[0]] = 1;
        for (int i = 1; i < n; i++) {
            if ((s[i - 1] + 1) % 26 == s[i]) {
                len++;
            } else {
                len = 1;
            }
            dp[s[i]] = Math.max(dp[s[i]], len);
        }

        return Arrays.stream(dp).sum();
    }
}
